﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Back.Xinkui.Entity.Buylead;
using CommonFramework.Utility;
using Back.Xinkui.DataAccess.Buylead;
using Back.Xinkui.Common;

public partial class buylead_list : System.Web.UI.Page
{
    protected List<BuyleadListEntity> BuyleadList { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = ddlPageCount.SelectedValue.ToType<int>(10);
            BindBuyleadList();
        }
    }

    protected void BindBuyleadList()
    {
        string where = "";
        if (!string.IsNullOrEmpty(this.txtSubject.Text.Trim()))
        {
            where += " AND B.Subject Like '%" + this.txtSubject.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.txtCompanyName.Text.Trim()))
        {
            where += " AND C.CompanyName Like '%" + this.txtCompanyName.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.txtEmail.Text.Trim()))
        {
            where += " AND ISNULL(u.Email,un.Email) Like '%" + this.txtEmail.Text.Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(this.ddpStatus.SelectedValue))
        {
            where += " AND B.AuditStatus = " + this.ddpStatus.SelectedValue;
        }
        if (!string.IsNullOrEmpty(this.txtStartTime.Text))
        {
            where += " AND B.CreateDate >= '" + this.txtStartTime.Text + "'";
        }
        if (!string.IsNullOrEmpty(this.txtEndTime.Text))
        {
            where += " AND B.CreateDate <  '" + this.txtEndTime.Text + "'";
        }

        Pager page = new Pager { PageIndex = AspNetPager1.CurrentPageIndex, PageSize = AspNetPager1.PageSize };

        BuyleadList = BuyleadDataAccess.GetBuyleadList(where, page);

        AspNetPager1.RecordCount = page.TotalCount;
    }

    protected void btnSerach_Click(object sender, EventArgs e)
    {
        BindBuyleadList();
    }

    /// <summary>
    /// 翻页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindBuyleadList();
    }

    /// <summary>
    /// 切换每页显示数据行数
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlPageCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        AspNetPager1.PageSize = Convert.ToInt32(ddlPageCount.SelectedValue);
        BindBuyleadList();
    }
}